home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Source Code
/
Libraries
/
Graphic Elements 3
/
GEMisc
/
GridElement.c
< prev
next >
Wrap
Text File
|
1994-05-28
|
2KB
|
74 lines
/*
GridElement.h
A Graphic Element used to break up large background pictures for faster updating.
Makes a basic PICT element, then clones it as necessary to convert it to a
set of tiles with width elemWidth and height elemHeight.
The elements created are assigned sequential IDs beginning at startID.
NewGridPICT returns the first element created.
For convenience, the elements are linked through their masterGrafEl/slaveGrafEl
fields. The element with ID startID is the head of the list.
Copyright 1994 by Al Evans. All rights reserved.
3/1/94
*/
#include "GridElement.h"
#include "Rects.h"
GrafElPtr NewGridPICT(GEWorldPtr world, OSType startID, short plane, short resNum,
short mode, short xPos, short yPos, short elemWidth,
short elemHeight)
{
GrafElPtr firstElement;
GrafElPtr currElement;
GrafElPtr nextElement;
OSType currID = startID;
Rect totalRect, gridRect;
Rect tempRect;
firstElement = NewBasicPICT(world, currID, plane, resNum, mode, xPos, yPos);
if (firstElement == nil) return nil;
currElement = firstElement;
totalRect = currElement->graphRect;
gridRect = totalRect;
gridRect.right = gridRect.left + ScaleToWorld(world, elemWidth);
gridRect.bottom = gridRect.top + ScaleToWorld(world, elemHeight);
do {
tempRect = gridRect;
(void) RectsIntersect(&totalRect, &tempRect);
currElement->graphRect = tempRect;
RectOffset(&tempRect, ScaleToWorld(world,xPos), ScaleToWorld(world, yPos));
currElement->animationRect = tempRect;
RectOffset(&gridRect, ScaleToWorld(world, elemWidth), 0);
if (gridRect.left >= totalRect.right) {
RectOffset(&gridRect, 0, ScaleToWorld(world, elemHeight));
if (gridRect.top >= totalRect.bottom)
break; //Normal exit
gridRect.left = totalRect.left;
gridRect.right = gridRect.left + ScaleToWorld(world, elemWidth);
}
currID++;
nextElement = NewBasicPICT(world, currID, plane, resNum, mode, xPos, yPos);
if (nextElement == nil)
goto abort; //oops
currElement->slaveGrafEl = nextElement;
nextElement->masterGrafEl = currElement;
currElement = nextElement;
} while (1);
return firstElement;
abort:
DisposeGrafElement(world, firstElement->objectID);
return nil;
}